package com.mini.demos.webgame.codec;

import org.apache.mina.core.buffer.IoBuffer;

import com.mini.demos.webgame.msg.AbstractGameMsg;
import com.mini.demos.webgame.msg.JobMsg;
import com.mini.demos.webgame.util.Constants;
import com.mini.framework.communicate.mina.protocol.Msg;

public class JobEncoder extends AbstractEncoder {

	@Override
	public void encodeBody(AbstractGameMsg msg, IoBuffer buffer) {
		JobMsg jobMsg = (JobMsg)msg;
		try{
			buffer.putInt(jobMsg.getJobId());
			buffer.putInt(jobMsg.getJobType());
			buffer.putInt(jobMsg.getCostPrice());
			buffer.putInt(jobMsg.getCostTime());
			buffer.putInt(jobMsg.getGetPrice());
			buffer.putString(jobMsg.getUserName(), Constants.charset.newEncoder());
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	@Override
	public Class<? extends Msg> getMsgType() {
		return JobMsg.class;
	}

}
